package com.twu.biblioteca;

import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

import static java.lang.String.format;

/**
 * Created with IntelliJ IDEA.
 * User: Thoughtworker
 * Date: 8/22/13
 * Time: 5:26 PM
 * To change this template use File | Settings | File Templates.
 */
public class MovieCollection {
    PrintStream printStream;
    List<Movie> movieList;
    UserInputReader userInputReader;
    String heading = format("%-20s %-5s %-15s %-3s", "Movie", "Year", "Director", "Rating");

    MovieCollection(List<Movie> movieList, PrintStream printStream, UserInputReader userInputReader){
        this.movieList = movieList;
        this.printStream = printStream;
        this.userInputReader = userInputReader;
    }

    public Movie findMovie(String title) throws IOException {
        Movie foundMovie = null;
        for (Movie movie : movieList) {
            if (movie.getTitle().equals(title))
                foundMovie = movie;
        }
        return foundMovie;
    }

    public void displayMovieInfo(Movie movie) throws IOException {
        printStream.println(heading);
        printStream.println(movie.displayInfo());
    }

    public String getHeading() {
        return heading;
    }

    public void displayAllMovieTitles() {
        for (Movie movie : movieList) {
            printStream.println(movie.getTitle());
        }
    }
}
